<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 3.9.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"mjava.top","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":true},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="LinkedList和ArrayDeque都是通过实现了Deque这个接口来获得队列和栈的功能。而Deque这个接口通过继承Queue这个接口来取得队列功能，然后在这个基础进行扩展，实现了双端队列，由此可以获得栈的功能。为了空间能得到充分利用，ArrayDeque使用了循环队列；还有LinkedList可以插入null值，而ArrayDeque是不能插入null的。">
<meta name="keywords" content="Java,源码解析,ArrayDeque">
<meta property="og:type" content="article">
<meta property="og:title" content="【源码解析】你真的了解ArrayDeque嘛？">
<meta property="og:url" content="http://mjava.top/java/java-arraydeque-source-1/index.html">
<meta property="og:site_name" content="灰色World">
<meta property="og:description" content="LinkedList和ArrayDeque都是通过实现了Deque这个接口来获得队列和栈的功能。而Deque这个接口通过继承Queue这个接口来取得队列功能，然后在这个基础进行扩展，实现了双端队列，由此可以获得栈的功能。为了空间能得到充分利用，ArrayDeque使用了循环队列；还有LinkedList可以插入null值，而ArrayDeque是不能插入null的。">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://cdn.mjava.top/blog/20200108104246.jpg">
<meta property="og:image" content="http://cdn.mjava.top/blog/20200108104215.jpg">
<meta property="og:image" content="http://cdn.mjava.top/blog/20200108104300.jpg">
<meta property="og:image" content="http://cdn.mjava.top/blog/20200107134323.png">
<meta property="og:image" content="http://cdn.mjava.top/blog/20200107232905.png">
<meta property="og:image" content="http://cdn.mjava.top/blog/20200107235523.png">
<meta property="og:image" content="http://cdn.mjava.top/blog/20200108003104.png">
<meta property="og:image" content="http://cdn.mjava.top/blog/20200108003710.png">
<meta property="og:image" content="http://cdn.mjava.top/blog/20200108095155.png">
<meta property="og:image" content="http://cdn.mjava.top/blog/20200108103710.png">
<meta property="og:image" content="http://cdn.mjava.top/blog/20200108112208.jpg">
<meta property="og:image" content="http://cdn.mjava.top/blog/20200108114243.png">
<meta property="og:image" content="http://cdn.mjava.top/blog/20200108114844.jpg">
<meta property="og:image" content="http://cdn.mjava.top/blog/20200108131919.png">
<meta property="og:image" content="http://cdn.mjava.top/blog/20200108133154.jpg">
<meta property="og:image" content="http://cdn.mjava.top/blog/20200108134034.png">
<meta property="og:updated_time" content="2021-01-27T10:07:24.133Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="【源码解析】你真的了解ArrayDeque嘛？">
<meta name="twitter:description" content="LinkedList和ArrayDeque都是通过实现了Deque这个接口来获得队列和栈的功能。而Deque这个接口通过继承Queue这个接口来取得队列功能，然后在这个基础进行扩展，实现了双端队列，由此可以获得栈的功能。为了空间能得到充分利用，ArrayDeque使用了循环队列；还有LinkedList可以插入null值，而ArrayDeque是不能插入null的。">
<meta name="twitter:image" content="http://cdn.mjava.top/blog/20200108104246.jpg">

<link rel="canonical" href="http://mjava.top/java/java-arraydeque-source-1/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>【源码解析】你真的了解ArrayDeque嘛？ | 灰色World</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="灰色World" type="application/atom+xml"><!-- hexo-inject:begin --><!-- hexo-inject:end -->
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>

<body itemscope itemtype="http://schema.org/WebPage">
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">灰色World</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/greycode9" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener external nofollow noreferrer" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://mjava.top/java/java-arraydeque-source-1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="灰灰">
      <meta itemprop="description" content="浅水是喧哗的，深水是沉默的">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="灰色World">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          【源码解析】你真的了解ArrayDeque嘛？
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-01-08 14:00:51" itemprop="dateCreated datePublished" datetime="2020-01-08T14:00:51+00:00">2020-01-08</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-01-27 10:07:24" itemprop="dateModified" datetime="2021-01-27T10:07:24+00:00">2021-01-27</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
                </span>
            </span>

          
            <div class="post-description">LinkedList和ArrayDeque都是通过实现了Deque这个接口来获得队列和栈的功能。而Deque这个接口通过继承Queue这个接口来取得队列功能，然后在这个基础进行扩展，实现了双端队列，由此可以获得栈的功能。为了空间能得到充分利用，ArrayDeque使用了循环队列；还有LinkedList可以插入null值，而ArrayDeque是不能插入null的。</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <div class="output_wrapper" id="output_wrapper_id" style="font-size: 15px; color: rgb(62, 62, 62); line-height: 1.8; word-spacing: 2px; letter-spacing: 2px; font-family: 'Helvetica Neue', Helvetica, 'Hiragino Sans GB', 'Microsoft YaHei', Arial, sans-serif; background-image: linear-gradient(90deg, rgba(50, 0, 0, 0.05) 3%, rgba(0, 0, 0, 0) 3%), linear-gradient(360deg, rgba(50, 0, 0, 0.05) 3%, rgba(0, 0, 0, 0) 3%); background-size: 20px 20px; background-position: center center;"><blockquote style="line-height: inherit; display: block; padding: 15px 15px 15px 1rem; font-size: 0.9em; margin: 1em 0px; color: rgb(0, 0, 0); border-left: 5px solid rgb(202, 200, 96); background: rgb(239, 235, 233); overflow: auto; overflow-wrap: normal; word-break: normal;">
  <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 0px;">积千里跬步，汇万里江河；每天进步一点点，终有一天将成大佬</p>
</blockquote>
<h2 id="h" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(233, 90, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(233, 90, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">前言</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h2>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">上篇文章说<a href="https://mjava.top/java/java-linkedlist-source-1/" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration: none; color: rgb(30, 107, 184); overflow-wrap: break-word;">LinkedList</a>也可以实现<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">队列</code>和<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">栈</code>的功能，但是我们一般要用队列功能的话推荐使用<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">ArrayDeque</code>,因为他层是<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">数组</strong>，而队列和栈都是只要<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">操作头部或尾部</strong>，所以这样的话数组的性能就比链表快一点。</p>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;"><a href="https://mjava.top/java/java-linkedlist-source-1/" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration: none; color: rgb(30, 107, 184); overflow-wrap: break-word;">LinkedList</a>和<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">ArrayDeque</code>都是通过实现了<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">Deque</code>这个接口来获得<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">队列</code>和<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">栈</code>的功能。而<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">Deque</code>这个接口通过继承<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">Queue</code>这个接口来取得队列功能，然后在这个基础进行扩展，实现了<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">双端队列</code>，由此可以获得<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">栈</code>的功能。为了空间能得到充分利用，<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">ArrayDeque</code>使用了<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">循环队列</code>；还有<a href="https://mjava.top/java/java-linkedlist-source-1/" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration: none; color: rgb(30, 107, 184); overflow-wrap: break-word;">LinkedList</a>可以插入<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">null</code>值，而<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">ArrayDeque</code>是不能插入<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">null</code>的。</p>
<h2 id="h-1" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(233, 90, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(233, 90, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">什么是双端队列？</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h2>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">简单来说，就是两端都可以操作的队列（🌚说了和没说一样…）。哈哈，还是看图吧</p>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">一般队列是这样的：</p>
<figure style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><img src="http://cdn.mjava.top/blog/20200108104246.jpg" alt title style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; display: block; margin: 0px auto; max-width: 100%;"><figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption></figure>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">双端队列是这样的</p>
<figure style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><img src="http://cdn.mjava.top/blog/20200108104215.jpg" alt title style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; display: block; margin: 0px auto; max-width: 100%;"><figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption></figure>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;"><strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">总的来说，普通队列只可在头部删除元素和尾部添加元素，而双端队列头部和尾部都可以添加和删除元素</strong></p>
<h2 id="h-2" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(233, 90, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(233, 90, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">什么是循环队列？</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h2>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">不如说你定了个5容量大小的数组，你第一次插入的位置是下标为2，当你添加第4个元素的时候，他不会进行扩容，而是通过<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">头尾指针</strong>进行对比，然后把数据插入到下标为0的位置上。当<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">头尾指针相等时</strong>，表示这个队列数组已经满了，这时才会扩容。</p>
<figure style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><img src="http://cdn.mjava.top/blog/20200108104300.jpg" alt title style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; display: block; margin: 0px auto; max-width: 100%;"><figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption></figure>
<blockquote style="line-height: inherit; display: block; padding: 15px 15px 15px 1rem; font-size: 0.9em; margin: 1em 0px; color: rgb(0, 0, 0); border-left: 5px solid rgb(202, 200, 96); background: rgb(239, 235, 233); overflow: auto; overflow-wrap: normal; word-break: normal;">
  <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 0px;">这里的数组从上向下的顺序，有人会问为什么头尾指针都指向第三个方格呢？因为这边演示的是第一个元素插入到下标为2的位置嘛。。当然，<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">ArrayDeque</code>是从0开始的，所以初始化时头尾指针都是指向下标为0的位置上。</p>
</blockquote>
<h2 id="hdeque" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(233, 90, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(233, 90, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">Deque有什么？</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h2>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">话不多说，看图：</p>
<figure style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><img src="http://cdn.mjava.top/blog/20200107134323.png" alt title style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; display: block; margin: 0px auto; max-width: 100%;"><figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption></figure>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;"><code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">ArrayDeque</code>具体实现的方法主要在蓝色的方框里，其他两个颜色的方框都是通过调用蓝色方框里的这些方法来实现相关功能的，可以再看一张我画的脑图：</p>
<figure style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><img src="http://cdn.mjava.top/blog/20200107232905.png" alt title style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; display: block; margin: 0px auto; max-width: 100%;"><figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption></figure>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">这边队列的每种功能都有两个方法，其中<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">add()</code>，<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">remove()</code>，<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">element()</code>如果操作失败会<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">报异常</strong>，<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">offer()</code>，<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">poll()</code>，<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">peek()</code>操作失败会<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">返回null或者false</strong></p>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">其实真正用到的就<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">深红色方框</strong>里写的这些方法，所以本文我就说这四个方法，<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">addLast()</code>，<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">pollFirst</code>，<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">getFirst()</code>，<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">addFirst()</code>，<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">peekFirst</code>；</p>
<h2 id="h-3" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(233, 90, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(233, 90, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">内部变量</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h2>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">ArrayDeque内部就只有4个变量，<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">对象数组element[]</strong>，<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">头指针head</strong>，<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">尾指针tail</strong>，<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">MIN_INITIAL_CAPACITY表示最小初始化容量为8</strong></p>
<figure style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><img src="http://cdn.mjava.top/blog/20200107235523.png" alt title style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; display: block; margin: 0px auto; max-width: 100%;"><figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption></figure>
<h2 id="h-4" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(233, 90, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(233, 90, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">构造方法</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h2>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">构造方法和其他集合一样，有<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">有参构造</strong>和<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">无参构造</strong></p>
<h3 id="h-5" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(150, 100, 50); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">无参构造</span></h3>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">很简单，直接初始化一个<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">容量为16</strong>的对象数组</p>
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; background: url('./school-book.png') rgb(246, 246, 174); border-top: 2px solid rgb(210, 232, 185); border-bottom: 1px solid rgb(210, 232, 185);"><code class="java language-java hljs" style="overflow-wrap: break-word; margin: 0px 2px; background: rgb(248, 248, 248); font-weight: normal; word-spacing: 0px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; overflow-x: auto; padding: 15px 0.5em 0.5em 30px; font-size: 11px; line-height: 16px; color: rgb(62, 89, 21); white-space: pre !important; word-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-function" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(44, 0, 159); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">ArrayDeque</span><span class="hljs-params" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">()</span>&nbsp;</span>{<br>&nbsp;&nbsp;&nbsp;&nbsp;elements&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;Object[<span class="hljs-number" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">16</span>];<br>}<br></code></pre>
<h3 id="h-6" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(150, 100, 50); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">有参构造</span></h3>
<h4 id="hint" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; font-size: 1.2em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">传入参数为int数</span></h4>
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; background: url('./school-book.png') rgb(246, 246, 174); border-top: 2px solid rgb(210, 232, 185); border-bottom: 1px solid rgb(210, 232, 185);"><code class="java language-java hljs" style="overflow-wrap: break-word; margin: 0px 2px; background: rgb(248, 248, 248); font-weight: normal; word-spacing: 0px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; overflow-x: auto; padding: 15px 0.5em 0.5em 30px; font-size: 11px; line-height: 16px; color: rgb(62, 89, 21); white-space: pre !important; word-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-function" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(44, 0, 159); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">ArrayDeque</span><span class="hljs-params" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">(<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">int</span>&nbsp;numElements)</span>&nbsp;</span>{<br>&nbsp;&nbsp;&nbsp;&nbsp;allocateElements(numElements);<br>}<br></code></pre>
<ul style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; padding-left: 32px; list-style-type: disc;">
<li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">allocateElements(int numElements)</strong>分配空数组以容纳给定数量的元素。</li>
</ul>
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; background: url('./school-book.png') rgb(246, 246, 174); border-top: 2px solid rgb(210, 232, 185); border-bottom: 1px solid rgb(210, 232, 185);"><code class="java language-java hljs" style="overflow-wrap: break-word; margin: 0px 2px; background: rgb(248, 248, 248); font-weight: normal; word-spacing: 0px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; overflow-x: auto; padding: 15px 0.5em 0.5em 30px; font-size: 11px; line-height: 16px; color: rgb(62, 89, 21); white-space: pre !important; word-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-function" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">private</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">void</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(44, 0, 159); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">allocateElements</span><span class="hljs-params" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">(<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">int</span>&nbsp;numElements)</span>&nbsp;</span>{<br>&nbsp;&nbsp;&nbsp;&nbsp;elements&nbsp;=&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;Object[calculateSize(numElements)];<br>}<br></code></pre>
<ul style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; padding-left: 32px; list-style-type: disc;">
<li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">calculateSize(int numElements)</strong>调整传入的值大小</li>
</ul>
<figure style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><img src="http://cdn.mjava.top/blog/20200108003104.png" alt title style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; display: block; margin: 0px auto; max-width: 100%;"><figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption></figure>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;"><strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">上面的算法中用到了位运算，如果不了解位运算的话，可以看<a href="https://mjava.top/java/java-base-wei/" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration: none; color: rgb(30, 107, 184); overflow-wrap: break-word;">位运算</a>这篇文章。这里把数值设置成2的n次方(是整数次)，是为了满足下面要说的<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">循环队列</code>这个算法</strong></p>
<h4 id="h-7" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; font-size: 1.2em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">传入的参数为集合对象</span></h4>
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; background: url('./school-book.png') rgb(246, 246, 174); border-top: 2px solid rgb(210, 232, 185); border-bottom: 1px solid rgb(210, 232, 185);"><code class="java language-java hljs" style="overflow-wrap: break-word; margin: 0px 2px; background: rgb(248, 248, 248); font-weight: normal; word-spacing: 0px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; overflow-x: auto; padding: 15px 0.5em 0.5em 30px; font-size: 11px; line-height: 16px; color: rgb(62, 89, 21); white-space: pre !important; word-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-function" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(44, 0, 159); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">ArrayDeque</span><span class="hljs-params" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">(Collection&lt;?&nbsp;extends&nbsp;E&gt;&nbsp;c)</span>&nbsp;</span>{<br>&nbsp;&nbsp;&nbsp;&nbsp;allocateElements(c.size());<br>&nbsp;&nbsp;&nbsp;&nbsp;addAll(c);<br>}<br></code></pre>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">第一步调用了和上面一样的方法，这里多了个<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">addAll()</code>方法</p>
<ul style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; padding-left: 32px; list-style-type: disc;">
<li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">addAll(Collection<!--? extends E--> c)</strong></li>
</ul>
<figure style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><img src="http://cdn.mjava.top/blog/20200108003710.png" alt title style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; display: block; margin: 0px auto; max-width: 100%;"><figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption></figure>
<blockquote style="line-height: inherit; display: block; padding: 15px 15px 15px 1rem; font-size: 0.9em; margin: 1em 0px; color: rgb(0, 0, 0); border-left: 5px solid rgb(202, 200, 96); background: rgb(239, 235, 233); overflow: auto; overflow-wrap: normal; word-break: normal;">
  <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 0px;">这边复制时并没有用和<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">ArrayList</code>一样的<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">System.arraycopy()</code>方法，而是采用<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">for循环</code>来调用<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">add()</code>方法进行一个一个添加的；为什么这么做呢？因为<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">ArrayDeque</code>和其他集合不一样，它里面是不能有<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">null</code>值的，而其他集合里面有的是可以传<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">null</code>的，所以这边采用<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">add()</code>一个一个的加，<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">add()</code>方法如果传入的值为空的话，就会<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">报异常</strong>；（add()实际调用的是addLast()，下面再讲）</p>
</blockquote>
<h2 id="haddlast" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(233, 90, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(233, 90, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">addLast()</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h2>
<h3 id="h-8" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(150, 100, 50); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">源码解析</span></h3>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">这个方法的意思是添加数据到尾部，下面图片方框中的位与算法是实现循环队列这个功能的<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">核心算法</strong></p>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">还记得上面初始化时候，不管传入的是什么数值，最后出来的都是<span class="katex" style="font: 1.21em / 1.2 KaTeX_Main, 'Times New Roman', serif; text-indent: 0px; text-rendering: auto; font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 8px 3px;"><span class="katex-mathml" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; position: absolute; clip: rect(1px, 1px, 1px, 1px); padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;"></span><span class="katex-html" aria-hidden="true" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><span class="base" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; position: relative; display: inline-block; white-space: nowrap; width: min-content;"><span class="strut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; height: 0.664392em; vertical-align: 0em;"></span><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">2</span><span class="msupsub" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; text-align: left;"><span class="vlist-t" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-table; table-layout: fixed;"><span class="vlist-r" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: table-row;"><span class="vlist" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: table-cell; vertical-align: bottom; position: relative; height: 0.664392em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: block; height: 0px; position: relative; top: -3.063em; margin-right: 0.05em;"><span class="pstrut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; overflow: hidden; width: 0px; height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight" style="color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; font-size: 0.7em;"><span class="mord mathit mtight" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; font-family: KaTeX_Math; font-style: italic;">n</span></span></span></span></span></span></span></span></span></span></span>(整数次)方。这个算法就是<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">当<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">&amp;</code>右边为<span class="katex" style="font: 1.21em / 1.2 KaTeX_Main, 'Times New Roman', serif; text-indent: 0px; text-rendering: auto; font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 8px 3px;"><span class="katex-mathml" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; position: absolute; clip: rect(1px, 1px, 1px, 1px); padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;"></span><span class="katex-html" aria-hidden="true" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><span class="base" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; position: relative; display: inline-block; white-space: nowrap; width: min-content;"><span class="strut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; height: 0.747722em; vertical-align: -0.08333em;"></span><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">2</span><span class="msupsub" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; text-align: left;"><span class="vlist-t" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-table; table-layout: fixed;"><span class="vlist-r" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: table-row;"><span class="vlist" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: table-cell; vertical-align: bottom; position: relative; height: 0.664392em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: block; height: 0px; position: relative; top: -3.063em; margin-right: 0.05em;"><span class="pstrut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; overflow: hidden; width: 0px; height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight" style="color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; font-size: 0.7em;"><span class="mord mathit mtight" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; font-family: KaTeX_Math; font-style: italic;">n</span></span></span></span></span></span></span></span><span class="mspace" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; margin-right: 0.2222222222222222em;"></span><span class="mbin" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">−</span><span class="mspace" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; margin-right: 0.2222222222222222em;"></span></span><span class="base" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; position: relative; display: inline-block; white-space: nowrap; width: min-content;"><span class="strut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; height: 0.64444em; vertical-align: 0em;"></span><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">1</span></span></span></span>时，<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">&amp;</code>左边的数为正整数时，不管有多大，最后的结果永远&lt;=<span class="katex" style="font: 1.21em / 1.2 KaTeX_Main, 'Times New Roman', serif; text-indent: 0px; text-rendering: auto; font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 8px 3px;"><span class="katex-mathml" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; position: absolute; clip: rect(1px, 1px, 1px, 1px); padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;"></span><span class="katex-html" aria-hidden="true" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><span class="base" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; position: relative; display: inline-block; white-space: nowrap; width: min-content;"><span class="strut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; height: 0.664392em; vertical-align: 0em;"></span><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">2</span><span class="msupsub" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; text-align: left;"><span class="vlist-t" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-table; table-layout: fixed;"><span class="vlist-r" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: table-row;"><span class="vlist" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: table-cell; vertical-align: bottom; position: relative; height: 0.664392em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: block; height: 0px; position: relative; top: -3.063em; margin-right: 0.05em;"><span class="pstrut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; overflow: hidden; width: 0px; height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight" style="color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; font-size: 0.7em;"><span class="mord mathit mtight" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; font-family: KaTeX_Math; font-style: italic;">n</span></span></span></span></span></span></span></span></span></span></span>；当<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">&amp;</code>左边的数为0时，结果为0；当<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">&amp;</code>左边的数为负数时，-1=<span class="katex" style="font: 1.21em / 1.2 KaTeX_Main, 'Times New Roman', serif; text-indent: 0px; text-rendering: auto; font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 8px 3px;"><span class="katex-mathml" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; position: absolute; clip: rect(1px, 1px, 1px, 1px); padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;"></span><span class="katex-html" aria-hidden="true" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><span class="base" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; position: relative; display: inline-block; white-space: nowrap; width: min-content;"><span class="strut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; height: 0.747722em; vertical-align: -0.08333em;"></span><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">2</span><span class="msupsub" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; text-align: left;"><span class="vlist-t" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-table; table-layout: fixed;"><span class="vlist-r" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: table-row;"><span class="vlist" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: table-cell; vertical-align: bottom; position: relative; height: 0.664392em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: block; height: 0px; position: relative; top: -3.063em; margin-right: 0.05em;"><span class="pstrut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; overflow: hidden; width: 0px; height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight" style="color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; font-size: 0.7em;"><span class="mord mathit mtight" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; font-family: KaTeX_Math; font-style: italic;">n</span></span></span></span></span></span></span></span><span class="mspace" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; margin-right: 0.2222222222222222em;"></span><span class="mbin" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">−</span><span class="mspace" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; margin-right: 0.2222222222222222em;"></span></span><span class="base" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; position: relative; display: inline-block; white-space: nowrap; width: min-content;"><span class="strut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; height: 0.64444em; vertical-align: 0em;"></span><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">1</span></span></span></span></strong></p>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">举一些例子：当<span class="katex" style="font: 1.21em / 1.2 KaTeX_Main, 'Times New Roman', serif; text-indent: 0px; text-rendering: auto; font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 8px 3px;"><span class="katex-mathml" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; position: absolute; clip: rect(1px, 1px, 1px, 1px); padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;"></span><span class="katex-html" aria-hidden="true" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><span class="base" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; position: relative; display: inline-block; white-space: nowrap; width: min-content;"><span class="strut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; height: 0.664392em; vertical-align: 0em;"></span><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">2</span><span class="msupsub" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; text-align: left;"><span class="vlist-t" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-table; table-layout: fixed;"><span class="vlist-r" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: table-row;"><span class="vlist" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: table-cell; vertical-align: bottom; position: relative; height: 0.664392em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: block; height: 0px; position: relative; top: -3.063em; margin-right: 0.05em;"><span class="pstrut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; overflow: hidden; width: 0px; height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight" style="color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; font-size: 0.7em;"><span class="mord mathit mtight" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; font-family: KaTeX_Math; font-style: italic;">n</span></span></span></span></span></span></span></span><span class="mspace" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; margin-right: 0.2777777777777778em;"></span><span class="mrel" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">=</span><span class="mspace" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; margin-right: 0.2777777777777778em;"></span></span><span class="base" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; position: relative; display: inline-block; white-space: nowrap; width: min-content;"><span class="strut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; height: 0.64444em; vertical-align: 0em;"></span><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">8</span></span></span></span>，<span class="katex" style="font: 1.21em / 1.2 KaTeX_Main, 'Times New Roman', serif; text-indent: 0px; text-rendering: auto; font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 8px 3px;"><span class="katex-mathml" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; position: absolute; clip: rect(1px, 1px, 1px, 1px); padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;"></span><span class="katex-html" aria-hidden="true" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><span class="base" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; position: relative; display: inline-block; white-space: nowrap; width: min-content;"><span class="strut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; height: 0.747722em; vertical-align: -0.08333em;"></span><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">2</span><span class="msupsub" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; text-align: left;"><span class="vlist-t" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-table; table-layout: fixed;"><span class="vlist-r" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: table-row;"><span class="vlist" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: table-cell; vertical-align: bottom; position: relative; height: 0.664392em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: block; height: 0px; position: relative; top: -3.063em; margin-right: 0.05em;"><span class="pstrut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; overflow: hidden; width: 0px; height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight" style="color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; font-size: 0.7em;"><span class="mord mathit mtight" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; font-family: KaTeX_Math; font-style: italic;">n</span></span></span></span></span></span></span></span><span class="mspace" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; margin-right: 0.2222222222222222em;"></span><span class="mbin" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">−</span><span class="mspace" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; margin-right: 0.2222222222222222em;"></span></span><span class="base" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; position: relative; display: inline-block; white-space: nowrap; width: min-content;"><span class="strut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; height: 0.64444em; vertical-align: 0em;"></span><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">1</span><span class="mspace" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; margin-right: 0.2777777777777778em;"></span><span class="mrel" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">=</span><span class="mspace" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; margin-right: 0.2777777777777778em;"></span></span><span class="base" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; position: relative; display: inline-block; white-space: nowrap; width: min-content;"><span class="strut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; height: 0.64444em; vertical-align: 0em;"></span><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">7</span></span></span></span></p>
<ul style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; padding-left: 32px; list-style-type: disc;">
<li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">4&amp;7=4    9&amp;7=1    22&amp;7=6</span></li>
<li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">0&amp;7=0</span></li>
<li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">-1&amp;7=7    -2&amp;7=6    -8&amp;7=0</span></li>
</ul>
<figure style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><img src="http://cdn.mjava.top/blog/20200108095155.png" alt title style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; display: block; margin: 0px auto; max-width: 100%;"><figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption></figure>
<ul style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; padding-left: 32px; list-style-type: disc;">
<li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">doubleCapacity()</strong>扩容为原来的<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">2倍</strong></li>
</ul>
<figure style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><img src="http://cdn.mjava.top/blog/20200108103710.png" alt title style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; display: block; margin: 0px auto; max-width: 100%;"><figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption></figure>
<h3 id="h-9" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(150, 100, 50); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">流程图</span></h3>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">方便理解，我画下上扩容的流程图，比如head在中间：</p>
<figure style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><img src="http://cdn.mjava.top/blog/20200108112208.jpg" alt title style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; display: block; margin: 0px auto; max-width: 100%;"><figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption></figure>
<h2 id="hpollfirst" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(233, 90, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(233, 90, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">pollFirst()</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h2>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">移除头部数据</p>
<h3 id="h-10" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(150, 100, 50); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">源码解析</span></h3>
<figure style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><img src="http://cdn.mjava.top/blog/20200108114243.png" alt title style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; display: block; margin: 0px auto; max-width: 100%;"><figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption></figure>
<blockquote style="line-height: inherit; display: block; padding: 15px 15px 15px 1rem; font-size: 0.9em; margin: 1em 0px; color: rgb(0, 0, 0); border-left: 5px solid rgb(202, 200, 96); background: rgb(239, 235, 233); overflow: auto; overflow-wrap: normal; word-break: normal;">
  <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 0px;">删除的时候并没有像<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">ArrayList</code>一样移动数据，而只是移动了<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">head</code>指向的位置</p>
</blockquote>
<h3 id="h-11" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(150, 100, 50); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">流程图</span></h3>
<figure style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><img src="http://cdn.mjava.top/blog/20200108114844.jpg" alt title style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; display: block; margin: 0px auto; max-width: 100%;"><figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption></figure>
<h2 id="hgetfirstpeekfirst" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(233, 90, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(233, 90, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">getFirst()和peekFirst()</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h2>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">这两个方法都是一样的，都是直接返回<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">head</code>指向的数据，区别就是一个会抛异常，一个不会</p>
<h3 id="h-12" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(150, 100, 50); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">源码分析</span></h3>
<ul style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; padding-left: 32px; list-style-type: disc;">
<li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">getFirst()</strong></li>
</ul>
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; background: url('./school-book.png') rgb(246, 246, 174); border-top: 2px solid rgb(210, 232, 185); border-bottom: 1px solid rgb(210, 232, 185);"><code class="java language-java hljs" style="overflow-wrap: break-word; margin: 0px 2px; background: rgb(248, 248, 248); font-weight: normal; word-spacing: 0px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; overflow-x: auto; padding: 15px 0.5em 0.5em 30px; font-size: 11px; line-height: 16px; color: rgb(62, 89, 21); white-space: pre !important; word-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-function" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;E&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(44, 0, 159); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">getFirst</span><span class="hljs-params" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">()</span>&nbsp;</span>{<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-meta" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(230, 4, 21); word-wrap: inherit !important; word-break: inherit !important;">@SuppressWarnings</span>(<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(44, 0, 159); word-wrap: inherit !important; word-break: inherit !important;">"unchecked"</span>)<br>&nbsp;&nbsp;&nbsp;&nbsp;E&nbsp;result&nbsp;=&nbsp;(E)&nbsp;elements[head];<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">if</span>&nbsp;(result&nbsp;==&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">null</span>)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">throw</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">new</span>&nbsp;NoSuchElementException();<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">return</span>&nbsp;result;<br>}<br></code></pre>
<ul style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; padding-left: 32px; list-style-type: disc;">
<li style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; margin-bottom: 0.5em;"><strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">peekFirst()</strong></li>
</ul>
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; background: url('./school-book.png') rgb(246, 246, 174); border-top: 2px solid rgb(210, 232, 185); border-bottom: 1px solid rgb(210, 232, 185);"><code class="java language-java hljs" style="overflow-wrap: break-word; margin: 0px 2px; background: rgb(248, 248, 248); font-weight: normal; word-spacing: 0px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; overflow-x: auto; padding: 15px 0.5em 0.5em 30px; font-size: 11px; line-height: 16px; color: rgb(62, 89, 21); white-space: pre !important; word-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-function" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;E&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(44, 0, 159); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">peekFirst</span><span class="hljs-params" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">()</span>&nbsp;</span>{<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(230, 4, 21); word-wrap: inherit !important; word-break: inherit !important;">//&nbsp;elements[head]&nbsp;is&nbsp;null&nbsp;if&nbsp;deque&nbsp;empty</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">return</span>&nbsp;(E)&nbsp;elements[head];<br>}<br></code></pre>
<h2 id="haddfirst" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(233, 90, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(233, 90, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">addFirst()</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h2>
<h3 id="h-13" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(150, 100, 50); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">源码解析</span></h3>
<figure style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><img src="http://cdn.mjava.top/blog/20200108131919.png" alt title style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; display: block; margin: 0px auto; max-width: 100%;"><figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption></figure>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">这里还是用了上面讲了位与算法，算出<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">head</code>的值，然后插入数据</p>
<h3 id="h-14" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(150, 100, 50); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">流程图</span></h3>
<figure style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><img src="http://cdn.mjava.top/blog/20200108133154.jpg" alt title style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; display: block; margin: 0px auto; max-width: 100%;"><figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption></figure>
<h2 id="hclear" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(233, 90, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(233, 90, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">clear()</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h2>
<h3 id="h-15" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(150, 100, 50); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">源码解析</span></h3>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">清空这个操作是从<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">head</code>指向的元素开始删除，直到<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">head</code>=<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">tail</code>，清空完成；</p>
<figure style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><img src="http://cdn.mjava.top/blog/20200108134034.png" alt title style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; display: block; margin: 0px auto; max-width: 100%;"><figcaption style="line-height: inherit; margin: 0px; padding: 0px; margin-top: 10px; text-align: center; color: rgb(153, 153, 153); font-size: 0.7em;"></figcaption></figure>
<h2 id="hsize" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(233, 90, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(233, 90, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">size()</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h2>
<blockquote style="line-height: inherit; display: block; padding: 15px 15px 15px 1rem; font-size: 0.9em; margin: 1em 0px; color: rgb(0, 0, 0); border-left: 5px solid rgb(202, 200, 96); background: rgb(239, 235, 233); overflow: auto; overflow-wrap: normal; word-break: normal;">
  <p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 0px;">这个获取队列的大小也是用了上面讲的位与算法，用尾部减去了头部，然后位与数组的长度-1。为什么要这么弄呢？直接向<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">ArrayList</code>和<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">LinkedList</code>一样定义个size不好嘛？<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">你不觉得这样更方便吗？少了一个变量，就少维护了一个变量，就少了一个安全隐患啊</strong></p>
</blockquote>
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; background: url('./school-book.png') rgb(246, 246, 174); border-top: 2px solid rgb(210, 232, 185); border-bottom: 1px solid rgb(210, 232, 185);"><code class="java language-java hljs" style="overflow-wrap: break-word; margin: 0px 2px; background: rgb(248, 248, 248); font-weight: normal; word-spacing: 0px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; overflow-x: auto; padding: 15px 0.5em 0.5em 30px; font-size: 11px; line-height: 16px; color: rgb(62, 89, 21); white-space: pre !important; word-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-function" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;"><span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">public</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">int</span>&nbsp;<span class="hljs-title" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(44, 0, 159); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">size</span><span class="hljs-params" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">()</span>&nbsp;</span>{<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(0, 85, 153); font-weight: bold; word-wrap: inherit !important; word-break: inherit !important;">return</span>&nbsp;(tail&nbsp;-&nbsp;head)&nbsp;&amp;&nbsp;(elements.length&nbsp;-&nbsp;<span class="hljs-number" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; word-wrap: inherit !important; word-break: inherit !important;">1</span>);<br>}<br></code></pre>
<h2 id="h-16" style="color: inherit; line-height: inherit; padding: 0px; margin: 1.6em 0px; font-weight: bold; border-bottom: 2px solid rgb(233, 90, 96); font-size: 1.3em;"><span style="font-size: inherit; line-height: inherit; margin: 0px; display: inline-block; font-weight: normal; background: rgb(233, 90, 96); color: rgb(255, 255, 255); padding: 3px 10px 1px; border-top-right-radius: 3px; border-top-left-radius: 3px; margin-right: 3px;">总结</span><span style="display: inline-block; vertical-align: bottom; border-bottom: 36px solid rgb(239, 235, 233); border-right: 20px solid transparent;"> </span></h2>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">上面的方法基本上有<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">位与</code>这个算法的身影，可见这个是核心了；如果不了解位运算的话，可以看<a href="https://mjava.top/java/java-base-wei/" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration: none; color: rgb(30, 107, 184); overflow-wrap: break-word;">位运算</a>这篇文章；</p>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;">核心算法：</p>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;"><strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">当<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">&amp;</code>右边为<span class="katex" style="font: 1.21em / 1.2 KaTeX_Main, 'Times New Roman', serif; text-indent: 0px; text-rendering: auto; font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 8px 3px;"><span class="katex-mathml" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; position: absolute; clip: rect(1px, 1px, 1px, 1px); padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;"></span><span class="katex-html" aria-hidden="true" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><span class="base" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; position: relative; display: inline-block; white-space: nowrap; width: min-content;"><span class="strut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; height: 0.747722em; vertical-align: -0.08333em;"></span><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">2</span><span class="msupsub" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; text-align: left;"><span class="vlist-t" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-table; table-layout: fixed;"><span class="vlist-r" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: table-row;"><span class="vlist" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: table-cell; vertical-align: bottom; position: relative; height: 0.664392em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: block; height: 0px; position: relative; top: -3.063em; margin-right: 0.05em;"><span class="pstrut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; overflow: hidden; width: 0px; height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight" style="color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; font-size: 0.7em;"><span class="mord mathit mtight" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; font-family: KaTeX_Math; font-style: italic;">n</span></span></span></span></span></span></span></span><span class="mspace" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; margin-right: 0.2222222222222222em;"></span><span class="mbin" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">−</span><span class="mspace" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; margin-right: 0.2222222222222222em;"></span></span><span class="base" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; position: relative; display: inline-block; white-space: nowrap; width: min-content;"><span class="strut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; height: 0.64444em; vertical-align: 0em;"></span><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">1</span></span></span></span>时，<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">&amp;</code>左边的数为正整数时，不管有多大，最后的结果永远&lt;=<span class="katex" style="font: 1.21em / 1.2 KaTeX_Main, 'Times New Roman', serif; text-indent: 0px; text-rendering: auto; font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 8px 3px;"><span class="katex-mathml" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; position: absolute; clip: rect(1px, 1px, 1px, 1px); padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;"></span><span class="katex-html" aria-hidden="true" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><span class="base" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; position: relative; display: inline-block; white-space: nowrap; width: min-content;"><span class="strut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; height: 0.664392em; vertical-align: 0em;"></span><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">2</span><span class="msupsub" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; text-align: left;"><span class="vlist-t" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-table; table-layout: fixed;"><span class="vlist-r" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: table-row;"><span class="vlist" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: table-cell; vertical-align: bottom; position: relative; height: 0.664392em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: block; height: 0px; position: relative; top: -3.063em; margin-right: 0.05em;"><span class="pstrut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; overflow: hidden; width: 0px; height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight" style="color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; font-size: 0.7em;"><span class="mord mathit mtight" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; font-family: KaTeX_Math; font-style: italic;">n</span></span></span></span></span></span></span></span></span></span></span>；当<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">&amp;</code>左边的数为0时，结果为0；当<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">&amp;</code>左边的数为负数时，-1=<span class="katex" style="font: 1.21em / 1.2 KaTeX_Main, 'Times New Roman', serif; text-indent: 0px; text-rendering: auto; font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 8px 3px;"><span class="katex-mathml" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; position: absolute; clip: rect(1px, 1px, 1px, 1px); padding: 0px; border: 0px; height: 1px; width: 1px; overflow: hidden;"></span><span class="katex-html" aria-hidden="true" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><span class="base" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; position: relative; display: inline-block; white-space: nowrap; width: min-content;"><span class="strut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; height: 0.747722em; vertical-align: -0.08333em;"></span><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;"><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">2</span><span class="msupsub" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; text-align: left;"><span class="vlist-t" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-table; table-layout: fixed;"><span class="vlist-r" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: table-row;"><span class="vlist" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: table-cell; vertical-align: bottom; position: relative; height: 0.664392em;"><span style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: block; height: 0px; position: relative; top: -3.063em; margin-right: 0.05em;"><span class="pstrut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; overflow: hidden; width: 0px; height: 2.7em;"></span><span class="sizing reset-size6 size3 mtight" style="color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; font-size: 0.7em;"><span class="mord mathit mtight" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; font-family: KaTeX_Math; font-style: italic;">n</span></span></span></span></span></span></span></span><span class="mspace" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; margin-right: 0.2222222222222222em;"></span><span class="mbin" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">−</span><span class="mspace" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; margin-right: 0.2222222222222222em;"></span></span><span class="base" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; position: relative; display: inline-block; white-space: nowrap; width: min-content;"><span class="strut" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px; display: inline-block; height: 0.64444em; vertical-align: 0em;"></span><span class="mord" style="font-size: inherit; color: inherit; line-height: inherit; margin: 0px; padding: 0px;">1</span></span></span></span></strong></p>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;"><code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">ArrayDeque</code>无参构造方法是直接初始化一个容量为16的空数组，而上篇<a href="https://mjava.top/java/java-arraylist-source-1" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; text-decoration: none; color: rgb(30, 107, 184); overflow-wrap: break-word;">ArrayList</a>文章里，它无参构造方法是初始化了一个<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">空数组</strong>，在第一次添加数据的时候才进行扩容到10；</p>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;"><code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">ArrayDeque</code>每次扩容为原来数组长度的<strong style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; font-weight: bold; color: rgb(233, 105, 0);">2倍</strong></p>
<p style="font-size: inherit; color: inherit; line-height: inherit; padding: 0px; margin: 1.7em 0px;"><code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">ArrayDeque</code>不能插入<code style="font-size: inherit; line-height: inherit; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0px 2px; color: rgb(248, 35, 117); background: rgb(248, 248, 248);">null</code>值</p></div>
    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Java/" rel="tag"># Java</a>
              <a href="/tags/源码解析/" rel="tag"># 源码解析</a>
              <a href="/tags/ArrayDeque/" rel="tag"># ArrayDeque</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/java/java-linkedlist-source-1/" rel="prev" title="【源码解析】想了解LinkedList？看这篇文章就对了">
      <i class="fa fa-chevron-left"></i> 【源码解析】想了解LinkedList？看这篇文章就对了
    </a></div>
      <div class="post-nav-item">
    <a href="/recommend/recommend-tool-1/" rel="next" title="【转】免费可商用，最值得收藏的10个插画素材网站">
      【转】免费可商用，最值得收藏的10个插画素材网站 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#h"><span class="nav-number">1.</span> <span class="nav-text">前言 </span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#h-1"><span class="nav-number">2.</span> <span class="nav-text">什么是双端队列？ </span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#h-2"><span class="nav-number">3.</span> <span class="nav-text">什么是循环队列？ </span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#hdeque"><span class="nav-number">4.</span> <span class="nav-text">Deque有什么？ </span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#h-3"><span class="nav-number">5.</span> <span class="nav-text">内部变量 </span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#h-4"><span class="nav-number">6.</span> <span class="nav-text">构造方法 </span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#h-5"><span class="nav-number">6.1.</span> <span class="nav-text">无参构造</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#h-6"><span class="nav-number">6.2.</span> <span class="nav-text">有参构造</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#hint"><span class="nav-number">6.2.1.</span> <span class="nav-text">传入参数为int数</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#h-7"><span class="nav-number">6.2.2.</span> <span class="nav-text">传入的参数为集合对象</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#haddlast"><span class="nav-number">7.</span> <span class="nav-text">addLast() </span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#h-8"><span class="nav-number">7.1.</span> <span class="nav-text">源码解析</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#h-9"><span class="nav-number">7.2.</span> <span class="nav-text">流程图</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#hpollfirst"><span class="nav-number">8.</span> <span class="nav-text">pollFirst() </span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#h-10"><span class="nav-number">8.1.</span> <span class="nav-text">源码解析</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#h-11"><span class="nav-number">8.2.</span> <span class="nav-text">流程图</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#hgetfirstpeekfirst"><span class="nav-number">9.</span> <span class="nav-text">getFirst()和peekFirst() </span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#h-12"><span class="nav-number">9.1.</span> <span class="nav-text">源码分析</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#haddfirst"><span class="nav-number">10.</span> <span class="nav-text">addFirst() </span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#h-13"><span class="nav-number">10.1.</span> <span class="nav-text">源码解析</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#h-14"><span class="nav-number">10.2.</span> <span class="nav-text">流程图</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#hclear"><span class="nav-number">11.</span> <span class="nav-text">clear() </span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#h-15"><span class="nav-number">11.1.</span> <span class="nav-text">源码解析</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#hsize"><span class="nav-number">12.</span> <span class="nav-text">size() </span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#h-16"><span class="nav-number">13.</span> <span class="nav-text">总结 </span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">灰灰</p>
  <div class="site-description" itemprop="description">浅水是喧哗的，深水是沉默的</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">59</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">16</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">56</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/greycode9" title="GitHub → https://github.com/greycode9" rel="noopener external nofollow noreferrer" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:zhengminghui99@gmail.com" title="E-Mail → mailto:zhengminghui99@gmail.com" rel="noopener external nofollow noreferrer" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title"><i class="fa fa-link fa-fw"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="https://www.yuque.com/huihui-r7gwx" title="https://www.yuque.com/huihui-r7gwx" rel="noopener external nofollow noreferrer" target="_blank">语雀</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        
  <div class="beian"><a href="https://beian.miit.gov.cn" rel="noopener external nofollow noreferrer" target="_blank">赣ICP备17003482号 </a>
  </div>

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">灰灰</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io" class="theme-link" rel="noopener external nofollow noreferrer" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org" class="theme-link" rel="noopener external nofollow noreferrer" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>
<script src="/js/utils.js"></script><script src="/js/motion.js"></script>
<script src="/js/schemes/muse.js"></script>
<script src="/js/next-boot.js"></script>



  




  <script src="/js/local-search.js"></script>












  

  
      

<script>
  if (typeof MathJax === 'undefined') {
    window.MathJax = {
      loader: {
          load: ['[tex]/mhchem'],
        source: {
          '[tex]/amsCd': '[tex]/amscd',
          '[tex]/AMScd': '[tex]/amscd'
        }
      },
      tex: {
        inlineMath: {'[+]': [['$', '$']]},
          packages: {'[+]': ['mhchem']},
        tags: 'ams'
      },
      options: {
        renderActions: {
          findScript: [10, doc => {
            document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
              const display = !!node.type.match(/; *mode=display/);
              const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
              const text = document.createTextNode('');
              node.parentNode.replaceChild(text, node);
              math.start = {node: text, delim: '', n: 0};
              math.end = {node: text, delim: '', n: 0};
              doc.math.push(math);
            });
          }, '', false],
          insertedScript: [200, () => {
            document.querySelectorAll('mjx-container').forEach(node => {
              let target = node.parentNode;
              if (target.nodeName.toLowerCase() === 'li') {
                target.parentNode.classList.add('has-jax');
              }
            });
          }, '', false]
        }
      }
    };
    (function () {
      var script = document.createElement('script');
      script.src = '//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';
      script.defer = true;
      document.head.appendChild(script);
    })();
  } else {
    MathJax.startup.document.state(0);
    MathJax.texReset();
    MathJax.typeset();
  }
</script><!-- hexo-inject:begin --><!-- hexo-inject:end -->

    

  

</body>
</html>
